<!--
 * @Description: 
 * @Version: V1.0.0
 * @Author: 周艳凯 484894717@qq.com
 * @Date: 2024-09-27 16:48:55
 * @LastEditors: 周艳凯 484894717@qq.com
 * @LastEditTime: 2024-10-15 13:32:03
 * @FilePath: index.vue
 * Copyright 2024 Marvin, All Rights Reserved. 
 * 2024-09-27 16:48:55
-->
<template>
  <div v-if="visible" :class="classNames">
    <div class="arco-alert-icon"></div>
    <div class="arco-alert-body">
      <div v-if="isTitle" class="arco-alert-title">
        <slot name="title"> {{ title }}</slot>
      </div>
      <div class="arco-alert-content">
        <slot></slot>
      </div>
    </div>
    <!-- 更多 -->
    <div v-if="isaction" class="arco-alert-action">
      <slot name="action"></slot>
    </div>
    <!-- 关闭 -->
    <div v-if="closable" class="arco-alert-close-btn" @click="handleClose">
      <div class="arco-icon-hover">
        <svgIcon name="guanbi1"></svgIcon>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, ref } from "vue";
import svgIcon from "../arco-icon/index.vue";
const icon = defineComponent({
  name: "Card",
  options: {
    // 虚拟化节点
    virtualHost: true,
  },
  components: {
    svgIcon,
  },
  props: {
    type: {
      type: String,
      default: "info",
    },
    showIcon: {
      type: Boolean,
      default: true,
    },
    closable: {
      type: Boolean,
      default: false,
    },
    title: {
      type: String,
      default: "",
    },
    banner: {
      type: Boolean,
      default: false,
    },
    center: {
      type: Boolean,
      default: false,
    },
  },
  emits: {
    close: () => true,
    afterClose: () => true,
  },
  setup(props, { slots, emit }) {
    const prefixCls = "arco-alert";
    const visible = ref(true);
    const handleClose = () => {
      visible.value = false;
      emit("close");
    };
    const handleAfterLeave = () => {
      emit("afterClose");
    };

    const isaction = computed(() => {
      return Boolean(slots.action);
    });

    const isTitle = computed(() => {
      return Boolean(props.title || slots.title);
    });

    const classNames = computed(() => {
      return [
        prefixCls,
        `${prefixCls}-${props.type}`,
        {
          [`${prefixCls}-with-title`]: Boolean(props.title || slots.title),
          [`${prefixCls}-banner`]: props.banner,
          [`${prefixCls}-center`]: props.center,
        },
      ];
    });
    return {
      prefixCls,
      classNames,
      visible,
      isaction,
      isTitle,
      handleClose,
      handleAfterLeave,
    };
  },
});
export default icon;
</script>

<style scoped lang="scss">
@import "./index.scss";
</style>
